/*
 * AC
 * DP
 **/
#include <stdio.h>

int elevation[250][250];
int n, b, k;
int query_row, query_col;

int fun();
int main(int argc, char **argv)
{
	int i, j;
	scanf("%d %d %d", &n, &b, &k);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			scanf("%d", &elevation[i][j]);
		}
	}
	for (i = 0; i < k; i++) {
		scanf("%d %d", &query_row, &query_col);
		query_row--;
		query_col--;
		printf("%d\n", fun());
	}
	return 0;
}

int fun()
{
	int i, j, maxx = 0, minn = 250;

	for (i = query_row; i < query_row + b; i++) {
		for (j = query_col; j < query_col + b; j++) {
			if (maxx < elevation[i][j])
				maxx = elevation[i][j];
			if (minn > elevation[i][j])
				minn = elevation[i][j];
		}
	}
	return maxx - minn;
}
